// Copyright (C) 2002 IFOnlyRT Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official SVN repository and contact information can be found at
// http://code.google.com/p/ifonlyrt/

/*
 * CColor.cpp
 *
 *  Created on: 16 oct. 2009
 *      Author: Maxime Gaudin
 */

#include "CColor.hpp"

const CColor CColor::Black 	(0, 0, 0);
const CColor CColor::White 	(1, 1, 1);
const CColor CColor::Red 	(1, 0, 0);
const CColor CColor::Green 	(0, 1, 0);
const CColor CColor::Blue 	(0, 0, 1);

// Constructeurs ================================================
CColor::CColor()
: R(0)
, G(0)
, B(0)
{ }

CColor::CColor(const double cR, const double cG, const double cB)
: R(cR)
, G(cG)
, B(cB)
{ }

CColor::CColor(const double Value)
: R(Value)
, G(Value)
, B(Value)
{ }

CColor::CColor(const CColor& C2)
: R(C2.R)
, G(C2.G)
, B(C2.B)
{ }
// ==============================================================

// Méthodes publiques ==================
// En mode poilu !
void CColor::Saturate()
{
	R = (R < 0) ? 0 : ((R > 1) ? 1 : R);
	G = (G < 0) ? 0 : ((G > 1) ? 1 : G);
	B = (B < 0) ? 0 : ((B > 1) ? 1 : B);
}
// ======================================

// Operateurs ========================================
CColor CColor::operator =(const CColor& C2)
{ return CColor(C2); }

double CColor::operator [](const uint i) const
{
	switch(i)
	{
	case(0):
			return R;
	case(1):
			return G;
	case(2):
			return B;
	default:
		return -1;
	}
}

CColor CColor::operator +(const CColor& C2)
{ return CColor(R + C2.R, G + C2.G, B + C2.B); }

CColor CColor::operator +=(const CColor& C2)
{
	R += C2.R;
	G += C2.G;
	B += C2.B;

	return (*this);
}

CColor CColor::operator -(const CColor& C2)
{ return CColor(R - C2.R, G - C2.G, B - C2.B); }

CColor CColor::operator -=(const CColor& C2)
{
	R -= C2.R;
	G -= C2.G;
	B -= C2.B;

	return (*this);
}

CColor CColor::operator *(const CColor& C2)
{ return CColor(R * C2.R, G * C2.G, B * C2.B); }

CColor CColor::operator *=(const CColor& C2)
{
	R *= C2.R;
	G *= C2.G;
	B *= C2.B;

	return (*this);
}

CColor CColor::operator *(const double Scalar)
{ return CColor(R * Scalar, G * Scalar, B * Scalar); }

CColor CColor::operator *=(const double Scalar)
{
	R *= Scalar;
	G *= Scalar;
	B *= Scalar;

	return (*this);
}

CColor CColor::operator /(const double Scalar)
{ return CColor(R / Scalar, G / Scalar, B / Scalar); }

CColor CColor::operator /=(const double Scalar)
{
	R /= Scalar;
	G /= Scalar;
	B /= Scalar;

	return (*this);
}
